package com.demo.crud.config;

import com.demo.crud.filter.MyFilter;
import com.demo.crud.listener.MyListener;
import com.demo.crud.servlet.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Servlet;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Desc:三大组件Servlet、Filter、Listener配置文件
 *
 * @author: keen
 * Date: 2019-06-07
 * Time: 21:35
 */
//@Configuration
public class MyServerConfig {
    @Bean
    public ServletRegistrationBean myServlet() {
        ServletRegistrationBean<Servlet> servletRegistrationBean =
                new ServletRegistrationBean<>(new MyServlet(), "/myServlet");
        return servletRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean myFilter() {
        FilterRegistrationBean<MyFilter> filterRegistrationBean  = new FilterRegistrationBean<>(new MyFilter());
        filterRegistrationBean.addUrlPatterns("/hello","/myServlet");
        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean myListener(){
        return new ServletListenerRegistrationBean(new MyListener());
    }
}
